package com.duobaoyu.dby.supply.admin.controller.config;

import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.channel.common.util.JasyptUtils;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.core.common.util.DeflaterUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName SupplyToolController
 * @Description 供应链工具Controller
 * @createTime 15:16:00 2023/11/08
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/tool")
@Api(value = "supply-tool", tags = "供应链工具")
public class SupplyToolController {

    /**
     * 压缩字符串解压工具类
     * @param message
     * @return
     */
    @PostMapping("/decompression")
    @ApiOperation(value = "压缩字符串解压工具类", notes = "压缩字符串解压工具类")
    @SupplySysLog(value = "压缩字符串解压工具类",operationType = OperationTypeEnum.SELECT)
    public R<String> decompression(@RequestBody @NotBlank(message = "解压字符串不能为空") String message) {
        return R.ok(DeflaterUtils.unzipString(message));
    }

    /**
     * 压缩字符串解压工具类
     * @param message
     * @return
     */
    @PostMapping("/compress")
    @ApiOperation(value = "字符串压缩工具类", notes = "字符串压缩工具类")
    @SupplySysLog(value = "字符串压缩工具类",operationType = OperationTypeEnum.SELECT)
    public R<String> compress(@RequestBody @NotBlank(message = "压缩字符串不能为空") String message) {
        return R.ok(DeflaterUtils.zipString(message));
    }

    /**
     * 对接渠道配置加密
     * @param message
     * @return
     */
    @GetMapping("/encrypt")
    @ApiOperation(value = "对接渠道配置加密", notes = "对接渠道配置加密")
    @SupplySysLog(value = "对接渠道配置加密",operationType = OperationTypeEnum.SELECT)
    public R<String> channelConfigEncrypt(@NotBlank(message = "密码字符串不能为空") String passWord, @NotBlank(message = "加密字符串不能为空") String message) {
        return R.ok(JasyptUtils.encryptPwd(passWord, message));
    }

    /**
     * 对接渠道配置解密
     * @param message
     * @return
     */
    @GetMapping("/decrypt")
    @ApiOperation(value = "对接渠道配置加密", notes = "对接渠道配置加密")
    @SupplySysLog(value = "对接渠道配置加密",operationType = OperationTypeEnum.SELECT)
    public R<String> channelConfigDecrypt(@NotBlank(message = "密码字符串不能为空") String passWord, @NotBlank(message = "解密字符串不能为空") String message) {
        return R.ok(JasyptUtils.decryptPwd(passWord, message));
    }
}
